package com.qf.controller;

import com.qf.pojo.Bookrack;
import com.qf.pojo.req.UserRack;
import com.qf.service.RackService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
/*
* 书架*/
@RestController
public class RackController {
    @Resource
    private RackService rackService;
    @RequestMapping("/findRackByUid/{uid}")
    public List<UserRack> findByUid(@PathVariable("uid")int uid){
        return rackService.findByUid(uid);
    }
    @RequestMapping("/findRackByUidAndBid/{uid}/{bid}")
    public UserRack findByUidAndBid(@PathVariable("uid")int uid,@PathVariable("bid") int bid){
        return rackService.findByUidAndBid(uid, bid);
    }
    @RequestMapping(value = "/addRack",method = RequestMethod.POST)
    public int add(@RequestBody Bookrack bookrack){
        UserRack byUidAndBid = rackService.findByUidAndBid(bookrack.getUid(), bookrack.getBid());
        if (byUidAndBid!=null){
            return 0;
        }else {
            int add = rackService.add(bookrack);
            if (add>0){
                return 1;
            }else {
                return 0;
            }
        }
    }
    @RequestMapping("/deleteRack/{uid}/{bid}")
    public int delete(@PathVariable("uid")int uid,@PathVariable("bid") int bid){
        int delete = rackService.delete(uid, bid);
        if (delete>0){
            return 1;
        }else {
            return 0;
        }
    }
}
